//
// Created by ct on 2021/9/22.
//
#include <stdio.h>
#include <string.h>

typedef struct mmmm {
    int n;
    char buf[128];
} my_string;


char *convert(char *s, int numRows) {
    if (numRows <2) {
        return s;
    }
    int len = (int) strlen(s);
//    printf("%d \n", len);
    char res[numRows][len];
    int res_r_l[numRows];
    for (int i = 0; i < numRows; ++i) {
        res_r_l[i] = 0;
    }
    int i = 0, flag = -1;

    for (int j = 0; j < len; ++j) {
       // printf("xianzai shi zai di %d hang \n",i);
        int res_i_len = res_r_l[i];
        res[i][res_i_len] = s[j];
        res_r_l[i]++;
     //   printf("xianzai shi zai di %d hang , 这行已经收集 %d 字符, zifushi :   %s  \n",i , res_i_len ,res[i]);
        if(i == 0 || i ==(numRows -1)){  // 到达边界开始折回
            flag = -flag;
        }
        i += flag;


        // 链接：https://leetcode-cn.com/problems/zigzag-conversion/solution/z-xing-fa-bu-ke-qu-jie-jue-zhe-ge-wen-ti-ofee/

    }
    int x = 0;
    for (int j = 0; j < numRows; ++j) {
        int res_i_len = res_r_l[j];
       // printf("%d ",res_i_len);
        for (int k = 0; k < res_i_len; ++k) {
         //   printf("%c ",res[j][k]);
            s[x] = res[j][k];
            x = x+ 1;
        }
    }

//    *s = 'x';

 //   printf("\n");
 //   printf("%s ", s);
    return s;
}



int main(int argc, char *argv[]) {
    char s[]= "AB";
    int numRows = 1;


    convert(s, numRows);

    printf("%s ",s);
    return 0;

}